<!DOCTYPE html>
<html lang="cn">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数组新增</title>
</head>

<body>

</body>

</html>
<script>
    // let myColor = ["red", "green"];
    // myColor.push("blue");

    // document.write(myColor);
    // document.write(myColor.length);

    // myColor.unshift("black", "white");
    // document.write("在前面加上白色黑色" + myColor);

    // 需求：将数组 [2, 0, 6, 1, 77, 0, 52, 0, 25, 7] 中的 0 去掉后，形成一个不包含 0 的新数组
    let arr1 = [2, 0, 6, 1, 77, 0, 52, 0, 25, 7];
    let arr2 = [];

    for (i = 0; i < arr1.length; i++) {
        if (arr1[i] != 0) {
            arr2.push(arr1[i]);
        }
    }
    document.write(arr2);
    // 数组删除
    arr2.splice(3, 1);
    document.write("splice后:" + arr2);

    arr2.pop();
    document.write("pop后:" + arr2);

    arr2.shift();
    document.write("shift后:" + arr2);

    // 数组修改
    for (i = 0; i < arr2.length; i++) {
        arr2[i] *= 10;
        //arr2[i]=arr2[i] * 10;
    }
    document.write("给每一项后都加0：" + arr2);
</script>